/**
 * Created with IntelliJ IDEA.
 * User: Thoughtworker
 * Date: 8/25/13
 * Time: 4:12 PM
 * To change this template use File | Settings | File Templates.
 */
public class Game {
    private Player player2;
    private Player player1;

    public Game(Player player1, Player player2) {
        this.player1 = player1;
        this.player2 = player2;
    }

    public String displayScore() {
        if (player1.getScore() == 40 && player2.getScore() == 40) {
            return "Deuce";
        }
        return player1.getScore() + "/" + player2.getScore();
    }

    public void scorePointPlayer(int playerNumber) {
        if (playerNumber == 1) {
            player1.scorePoint();
        } else if (playerNumber == 2) {
            player2.scorePoint();
        }
    }

    public Player getWinner() {
        if(player1.getScore() == 40 && player2.getScore() == 40){
            player1.setWinner(false);
            player2.setWinner(false);
            return null;
        }

        if (player1.isWinner())
            return player1;
        else if (player2.isWinner())
            return player2;

        return null;
    }
}
